<?
	  layout("/inc/win_layout.html",{title:sysTitle}){
    ?>

<div class="col-lg-4">
	<div class="panel" style="height:100%; width:100%; overflow: auto;">
		<div class="panel-heading">知识点管理</div>
		<div class="panel-heading" >
			<span class="subtitle">
				<button type="button" onclick="addUploadPoint(0);" class="btn btn-primary btn-green" style="width:80px;" id="savejiedian">新&nbsp;&nbsp;建</button>&nbsp;&nbsp;
				<button type="button" onclick="addUploadPoint(1);" class="btn btn-primary btn-green"  style="width:80px;">编&nbsp;&nbsp;辑</button>&nbsp;&nbsp;
				<button type="button" onclick="delAll();" class="btn btn-primary btn-green"  style="width:80px;">删&nbsp;&nbsp;除</button>
				
			</span>
		</div>
		<div class="panel-body" style="height: 396px;">
			<ul id="tree" class="ztree" style="width:360px;overflow: auto;">
				
			</ul>
		</div>
		
	</div>
</div>


<?} ?>

<script>
	var knowledgePointId = window.parent.getknowledgePointId();
	var index = parent.layer.getFrameIndex(window.name); 
	var id='';
	$(function() {
		initTree();
	});
	function initTree() {
		$.ajax({
			type : "post",
			data : {
			"id":knowledgePointId,
			},
			url : "getCommunityKnowledgePointList.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}

	function drawTree(data) {
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : false
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);

	}
	
	function onClick(e, treeId, treeNode) {
		id = treeNode.id;
	}
	//删除所有
	function delAll() {
		if (confirm("是否确认删除！")){
			$.ajax({
				type : "post",
				url : "deldeteCommunityKnowledgePoint.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					if(data[0].data == 'yes' ){
						layer.msg('删除成功！');
						id='';
						initTree(); 
					}else{
						layer.msg('删除失败！');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	
	
	//新增
	var addUploadType;
	function getaddUploadType() {
		return addUploadType;
	}
	function getknowledgePointId() {
		return knowledgePointId;
	}
	function getId() {
		return id;
	}
	function addUploadPoint(type) {
		addUploadType = type;
		if(type == '1' && '' == id ){
			layer.msg('请先选择知识点！');
            return null;
        }
		parent.layer.open({
			type : 2,
			title : '字典项管理',
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			area : [ '650px', '600px' ],
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["community-knowledge-point-addUpload.html?winName="+window.name+"&id="+knowledgePointId,'no'],
			yes: function(index,layer){
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.Page();
  	        },
				cancel : function(index) {
			}
		});
	} 
</script>